import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;


class SyntaxModifier {

public static void main(String[] args) throws IOException {
	String readfile = args[0];
	
	String in_directory="C:/Users/Ayse&Murat/workspace/froggy/samples/"+readfile;
	String out_directory="C:/Users/Ayse&Murat/workspace/froggy/validation/syntax/test-src/";
 	
	int index = readfile.lastIndexOf('.');
	String writefile1 = out_directory+readfile.substring(0, index) + "_001.kfrog";
	String writefile2 = out_directory+readfile.substring(0, index) + "_002.kfrog";
	String writefile3 = out_directory+readfile.substring(0, index) + "_003.kfrog";
	String writefile4 = out_directory+readfile.substring(0, index) + "_004.kfrog";
	String writefile5 = out_directory+readfile.substring(0, index) + "_005.kfrog";
	String writefile6 = out_directory+readfile.substring(0, index) + "_006.kfrog";
	String writefile7 = out_directory+readfile.substring(0, index) + "_007.kfrog";
	String writefile8 = out_directory+readfile.substring(0, index) + "_008.kfrog";
	String writefile9 = out_directory+readfile.substring(0, index) + "_009.kfrog";
	String writefile10 = out_directory+readfile.substring(0, index) + "_010.kfrog";
	String writefile11 = out_directory+readfile.substring(0, index) + "_011.kfrog";
	String writefile12 = out_directory+readfile.substring(0, index) + "_012.kfrog";
	String writefile13 = out_directory+readfile.substring(0, index) + "_013.kfrog";
	String writefile14 = out_directory+readfile.substring(0, index) + "_014.kfrog";
	String writefile15 = out_directory+readfile.substring(0, index) + "_015.kfrog";
	String writefile16 = out_directory+readfile.substring(0, index) + "_016.kfrog";
	String writefile17 = out_directory+readfile.substring(0, index) + "_017.kfrog";
	
	// add // comments at the bottom of each line
	// insert // comments between each line
	//	add two or more white spaces at the bottom of each line
	//	add two or more tabs at the bottom of each line
	//	add two or more newline at the bottom of each line

	FileOutputStream out1 = new FileOutputStream(writefile1);
	Scanner scan1= new Scanner(new BufferedReader(new FileReader(in_directory))).useDelimiter("\n");

	while (scan1.hasNext()) {
	    	StringBuffer buffer = new StringBuffer(scan1.next());
	    	String modified;
	    	if (scan1.hasNext()) {
	    		modified= buffer.append(" //TEST\t\r\n").toString();
	    	} else {
	    		modified= buffer.append("").toString();
	    	}
	        byte[] modifiedBytes= modified.getBytes();
	        
				out1.write(modifiedBytes);
		
	}    
	
	
	
	// after each whitespace, add Tab+Space+Newline+Comment+Newline
	FileOutputStream out2 = new FileOutputStream(writefile2);
	Scanner scan2= new Scanner(new BufferedReader(new FileReader(in_directory)));

	while (scan2.hasNext()) {
	    	StringBuffer buffer = new StringBuffer(scan2.next());
	    	String modified;
	    	if (scan2.hasNext()) {
	    		modified= buffer.append("\t \r\n\t /*TEST*/\r\n").toString();
	    	} else {
	    		modified= buffer.append("").toString();
	    	}
	        byte[] modifiedBytes= modified.getBytes();
	        
				out2.write(modifiedBytes);
		
	}    
	
	//	add tab, white spaces,and command before and after "="  
	FileOutputStream out3 = new FileOutputStream(writefile3);
	Scanner scan3= new Scanner(new BufferedReader(new FileReader(in_directory))).useDelimiter("=");

	while (scan3.hasNext()) {
	    	StringBuffer buffer = new StringBuffer(scan3.next());
	    	String modified;
	    	if (scan3.hasNext()) {
	    		modified= buffer.append("\t /*TEST*/ = \t  /*TEST*/").toString();
	    	} else {
	    		modified= buffer.append("").toString();
	    	}
	        byte[] modifiedBytes= modified.getBytes();
	        
				out3.write(modifiedBytes);
		
	}    
	
	// add tab, white spaces, command, and newline before and after "}"
	FileOutputStream out4 = new FileOutputStream(writefile4);
	Scanner scan4= new Scanner(new BufferedReader(new FileReader(in_directory))).useDelimiter("}");

	while (scan4.hasNext()) {
	    	StringBuffer buffer = new StringBuffer(scan4.next());
	    	String modified;
	    	if (scan4.hasNext()) {
	    		modified= buffer.append("\t \r\n\t /*TEST*/\r\n } \t \r\n\t /*TEST*/\r\n").toString();
	    	} else {
	    		modified= buffer.append("").toString();
	    	}
	        byte[] modifiedBytes= modified.getBytes();
	        
				out4.write(modifiedBytes);
	}    
	
	// checks * and *=
	String fstring5 = "";
	Scanner	s5 = new Scanner(new File(in_directory)).useDelimiter("\\*=");
		String st5 = s5.next();
		while (s5.hasNext()) {
			Scanner tmp5 = new Scanner(st5).useDelimiter("\\*");
			while (tmp5.hasNext()) {
				fstring5 += tmp5.next();
				if (!tmp5.hasNext())
					fstring5 +="";
				else 
				fstring5=fstring5+"\t \r\n\t /*TEST*/\r\n * \t \r\n\t /*TEST*/\r\n";
			}
			fstring5 += "\t \r\n\t /*TEST*/\r\n *= \t \r\n\t /*TEST*/\r\n";
			st5 = s5.next();
			
		}
		Scanner tmp5 = new Scanner(st5).useDelimiter("\\*");
		while (tmp5.hasNext()) {
			fstring5 += tmp5.next();
			if (!tmp5.hasNext())
				fstring5 +="";
			else 
				fstring5=fstring5+"\t \r\n\t /*TEST*/\r\n * \t \r\n\t /*TEST*/\r\n";
		}
		FileOutputStream out5 = new FileOutputStream(writefile5);
		byte[] stringBytes5= fstring5.getBytes();
		out5.write(stringBytes5);
	
		
		// checks % and %=
		String fstring6 = "";
		Scanner	s6 = new Scanner(new File(in_directory)).useDelimiter("%=");
			String st6 = s6.next();
			while (s6.hasNext()) {
				Scanner tmp6 = new Scanner(st6).useDelimiter("%");
				while (tmp6.hasNext()) {
					fstring6 += tmp6.next();
					if (!tmp6.hasNext())
						fstring6 +="";
					else 
					fstring6=fstring6+"\t \r\n\t /*TEST*/\r\n % \t \r\n\t /*TEST*/\r\n";
				}
				fstring6 += "\t \r\n\t /*TEST*/\r\n %= \t \r\n\t /*TEST*/\r\n";
				st6 = s6.next();
				
			}
			Scanner tmp6 = new Scanner(st6).useDelimiter("%");
			while (tmp6.hasNext()) {
				fstring6 += tmp6.next();
				if (!tmp6.hasNext())
					fstring6 +="";
				else 
					fstring6=fstring6+"\t \r\n\t /*TEST*/\r\n % \t \r\n\t /*TEST*/\r\n";
			}
			
			FileOutputStream out6 = new FileOutputStream(writefile6);
			byte[] stringBytes6= fstring6.getBytes();
			out6.write(stringBytes6);   
			
	// checks < and <=
	String fstring7 = "";
	Scanner	s7 = new Scanner(new File(in_directory)).useDelimiter("<=");
		String st7 = s7.next();
		while (s7.hasNext()) {
			Scanner tmp7 = new Scanner(st7).useDelimiter("<");
			while (tmp7.hasNext()) {
				fstring7 += tmp7.next();
				if (!tmp7.hasNext())
					fstring7 +="";
				else 
				fstring7=fstring7+"\t \r\n\t /*TEST*/\r\n < \t \r\n\t /*TEST*/\r\n";
			}
			fstring7 += "\t \r\n\t /*TEST*/\r\n <= \t \r\n\t /*TEST*/\r\n";
			st7 = s7.next();
			
		}
		Scanner tmp = new Scanner(st7).useDelimiter("<");
		while (tmp.hasNext()) {
			fstring7 += tmp.next();
			if (!tmp.hasNext())
				fstring7 +="";
			else 
				fstring7=fstring7+"\t \r\n\t /*TEST*/\r\n < \t \r\n\t /*TEST*/\r\n";
		}
		
		FileOutputStream out7 = new FileOutputStream(writefile7);
		byte[] stringBytes= fstring7.getBytes();
		out7.write(stringBytes);
	 

	
		// checks > and >=
		String fstring8 = "";
		Scanner	s8 = new Scanner(new File(in_directory)).useDelimiter(">=");
			String st8 = s8.next();
			while (s8.hasNext()) {
				Scanner tmp8 = new Scanner(st8).useDelimiter(">");
				while (tmp8.hasNext()) {
					fstring8 += tmp8.next();
					if (!tmp8.hasNext())
						fstring8 +="";
					else 
					fstring8=fstring8+"\t \r\n\t /*TEST*/\r\n > \t \r\n\t /*TEST*/\r\n";
				}
				fstring8 += "\t \r\n\t /*TEST*/\r\n >= \t \r\n\t /*TEST*/\r\n";
				st8 = s8.next();
				
			}
			Scanner tmp8 = new Scanner(st8).useDelimiter("<");
			while (tmp8.hasNext()) {
				fstring8 += tmp8.next();
				if (!tmp8.hasNext())
					fstring8 +="";
				else 
					fstring8=fstring8+"\t \r\n\t /*TEST*/\r\n < \t \r\n\t /*TEST*/\r\n";
			}
			
			FileOutputStream out8 = new FileOutputStream(writefile8);
			byte[] stringBytes8= fstring8.getBytes();
			out8.write(stringBytes8);
	
			
			// checks NOT and NOT=
			String fstring9 = "";
			Scanner	s9 = new Scanner(new File(in_directory)).useDelimiter("NOT=");
				String st9 = s9.next();
				while (s9.hasNext()) {
					Scanner tmp9 = new Scanner(st9).useDelimiter("NOT");
					while (tmp9.hasNext()) {
						fstring9 += tmp9.next();
						if (!tmp9.hasNext())
							fstring9 +="";
						else 
						fstring9=fstring9+"\t \r\n\t /*TEST*/\r\n - \t \r\n\t /*TEST*/\r\n";
					}
					fstring9 += "\t \r\n\t /*TEST*/\r\n NOT= \t \r\n\t /*TEST*/\r\n";
					st9 = s9.next();
					
				}
				Scanner tmp9 = new Scanner(st9).useDelimiter("NOT");
				while (tmp9.hasNext()) {
					fstring9 += tmp9.next();
					if (!tmp9.hasNext())
						fstring9 +="";
					else 
						fstring9=fstring9+"\t \r\n\t /*TEST*/\r\n NOT \t \r\n\t /*TEST*/\r\n";
				}
				
				FileOutputStream out9 = new FileOutputStream(writefile9);
				byte[] stringBytes9= fstring9.getBytes();
				out9.write(stringBytes9);    
	
	//checks AND
	FileOutputStream out10 = new FileOutputStream(writefile10);
	Scanner scan10= new Scanner(new BufferedReader(new FileReader(in_directory))).useDelimiter("AND");

	while (scan10.hasNext()) {
	    	StringBuffer buffer = new StringBuffer(scan10.next());
	    	String modified;
	    	if (scan10.hasNext()) {
	    		modified= buffer.append("\t \r\n\t /*TEST*/\r\n AND \t \r\n\t /*TEST*/\r\n").toString();
	    	} else {
	    		modified= buffer.append("").toString();
	    	}
	        byte[] modifiedBytes= modified.getBytes();
	        
				out10.write(modifiedBytes);
		
	}    
	
	//checks OR
	FileOutputStream out11 = new FileOutputStream(writefile11);
	Scanner scan11= new Scanner(new BufferedReader(new FileReader(in_directory))).useDelimiter("OR");

	while (scan11.hasNext()) {
	    	StringBuffer buffer = new StringBuffer(scan11.next());
	    	String modified;
	    	if (scan11.hasNext()) {
	    		modified= buffer.append("\t \r\n\t /*TEST*/\r\n OR \t \r\n\t /*TEST*/\r\n").toString();
	    	} else {
	    		modified= buffer.append("").toString();
	    	}
	        byte[] modifiedBytes= modified.getBytes();
	        
				out11.write(modifiedBytes);
		
	}    

	
	//checks {
	FileOutputStream out12 = new FileOutputStream(writefile12);
	Scanner scan12= new Scanner(new BufferedReader(new FileReader(in_directory))).useDelimiter("\\{");

	while (scan12.hasNext()) {
	    	StringBuffer buffer = new StringBuffer(scan12.next());
	    	String modified;
	    	if (scan12.hasNext()) {
	    		modified= buffer.append("\t \r\n\t /*TEST*/\r\n { \t \r\n\t /*TEST*/\r\n").toString();
	    	} else {
	    		modified= buffer.append("").toString();
	    	}
	        byte[] modifiedBytes= modified.getBytes();
	        
				out12.write(modifiedBytes);
	} 
	
	
	// checks + and +=
	String fstring13 = "";
	Scanner	s13 = new Scanner(new File(in_directory)).useDelimiter("\\+=");
		String st13 = s13.next();
		while (s13.hasNext()) {
			Scanner tmp13 = new Scanner(st13).useDelimiter("\\+");
			while (tmp13.hasNext()) {
				fstring13 += tmp13.next();
				if (!tmp13.hasNext())
					fstring13 +="";
				else 
				fstring13=fstring13+"\t \r\n\t /*TEST*/\r\n + \t \r\n\t /*TEST*/\r\n";
			}
			fstring13 += "\t \r\n\t /*TEST*/\r\n += \t \r\n\t /*TEST*/\r\n";
			st13 = s13.next();
			
		}
		Scanner tmp13 = new Scanner(st13).useDelimiter("\\+");
		while (tmp13.hasNext()) {
			fstring13 += tmp13.next();
			if (!tmp13.hasNext())
				fstring13 +="";
			else 
				fstring13=fstring13+"\t \r\n\t /*TEST*/\r\n + \t \r\n\t /*TEST*/\r\n";
		}
		
		FileOutputStream out13 = new FileOutputStream(writefile13);
		byte[] stringBytes13= fstring13.getBytes();
		out13.write(stringBytes13); 
		
	
	
		// checks - and -=
		String fstring14 = "";
		Scanner	s14 = new Scanner(new File(in_directory)).useDelimiter("-=");
			String st14 = s14.next();
			while (s14.hasNext()) {
				Scanner tmp14 = new Scanner(st14).useDelimiter("-");
				while (tmp14.hasNext()) {
					fstring14 += tmp14.next();
					if (!tmp14.hasNext())
						fstring14 +="";
					else 
					fstring14=fstring14+"\t \r\n\t /*TEST*/\r\n - \t \r\n\t /*TEST*/\r\n";
				}
				fstring14 += "\t \r\n\t /*TEST*/\r\n -= \t \r\n\t /*TEST*/\r\n";
				st14 = s14.next();
				
			}
			Scanner tmp14 = new Scanner(st14).useDelimiter("-");
			while (tmp14.hasNext()) {
				fstring14 += tmp14.next();
				if (!tmp14.hasNext())
					fstring14 +="";
				else 
					fstring14=fstring14+"\t \r\n\t /*TEST*/\r\n - \t \r\n\t /*TEST*/\r\n";
			}
			
			FileOutputStream out14 = new FileOutputStream(writefile14);
			byte[] stringBytes14= fstring14.getBytes();
			out14.write(stringBytes14);
			
			
			// checks (
			FileOutputStream out15 = new FileOutputStream(writefile15);
			Scanner scan15= new Scanner(new BufferedReader(new FileReader(in_directory))).useDelimiter("\\(");

			while (scan15.hasNext()) {
			    	StringBuffer buffer = new StringBuffer(scan15.next());
			    	String modified;
			    	if (scan15.hasNext()) {
			    		modified= buffer.append("\t \r\n\t /*TEST*/\r\n ( \t \r\n\t /*TEST*/\r\n").toString();
			    	} else {
			    		modified= buffer.append("").toString();
			    	}
			        byte[] modifiedBytes= modified.getBytes();
			        
						out15.write(modifiedBytes);
			}    
			
			//checks )
			FileOutputStream out16 = new FileOutputStream(writefile16);
			Scanner scan16= new Scanner(new BufferedReader(new FileReader(in_directory))).useDelimiter("\\)");

			while (scan16.hasNext()) {
			    	StringBuffer buffer = new StringBuffer(scan16.next());
			    	String modified;
			    	if (scan16.hasNext()) {
			    		modified= buffer.append("\t \r\n\t /*TEST*/\r\n ) \t \r\n\t /*TEST*/\r\n").toString();
			    	} else {
			    		modified= buffer.append("").toString();
			    	}
			        byte[] modifiedBytes= modified.getBytes();
			        
						out16.write(modifiedBytes);
			}    

			//checks ","
			FileOutputStream out17 = new FileOutputStream(writefile17);
			Scanner scan17= new Scanner(new BufferedReader(new FileReader(in_directory))).useDelimiter(",");

			while (scan17.hasNext()) {
			    	StringBuffer buffer = new StringBuffer(scan17.next());
			    	String modified;
			    	if (scan17.hasNext()) {
			    		modified= buffer.append("\t \r\n\t /*TEST*/\r\n , \t \r\n\t /*TEST*/\r\n").toString();
			    	} else {
			    		modified= buffer.append("").toString();
			    	}
			        byte[] modifiedBytes= modified.getBytes();
			        
						out17.write(modifiedBytes);
			}    
			
			
			
			
}
}


